﻿

using System;
using System.Configuration;
using good1.Web.Helpers;

namespace good1.Web.Model
{
    public class ProjectDetail : BaseViewData
    {
        private readonly int truncationLength = Convert.ToInt32(ConfigurationManager.AppSettings["description_truncation_length"]);
        private string tagLine;
        private string charityLogoUrl;
        private const string DefaultCharityLogo = "mygoodpoints_logo_smaller.png";


        public int TruncationLength { get {
            if (truncationLength==0)
            {
                return 200;
            }
            return truncationLength;
        }
        }
        
        //TODO now that we have a nice flattened object we could look at caching it when performance is raised in priority.
        public int Id { get; set; }
        public string Title { get; set; }
        public string Text { get; set; }
        public string TagLine { get
        {
            return string.IsNullOrEmpty(tagLine) ? TextTruncatedSummary : tagLine;
        }set{ tagLine = value;}
        }

        public string YourDonationCan { get; set; }
        public string ClosingDate { get; set; }
        public int Amount { get; set; }
        public int AmountRemaining { get; set; }
        public string PhotoUrl { get; set; }
        public string CharityName { get; set; }
        public string LocationName { get; set; }
        public string LocationId { get; set; }
        public string LocationCountryName { get; set; }
        public string PhotoThumbnailUrl { get; set; }
      
        public string CharityLogoUrl { get
        {
            return string.IsNullOrEmpty(charityLogoUrl) ? DefaultCharityLogo : charityLogoUrl;
        }set{ charityLogoUrl = value;}
        }

        
        public string CharityTagLine { get; set; }
        public string TitlePermaLink { get { return PermaLinks.CreatePermaLinkPhrase(Title); } }
        public string TextTruncatedSummary { get { return ((Text.LastIndexOf(" ") < TruncationLength + 1) ? Text : Text.Substring(0, Text.IndexOf(" ", TruncationLength))) + "..."; } }
    }
}
